package cn.lesaas.esb.poc.test;

import org.apache.camel.builder.RouteBuilder;

public class POCRoute1 extends RouteBuilder {
	@Override
	public void configure() throws Exception {
		from("direct:POC")
		.startupOrder(30)
		.setHeader("startTimestamp").method(DateTimeUtils.class, "toTimestamp")
		.setHeader("duration", xpath("/reqt/header/duration").resultType(int.class))
		.to("netty4:tcp://172.16.100.41:59999?allowDefaultCodec=false&encoder=#stringEncoder&decoder=#stringDecoder")				
		.choice()
		.when().xpath("/resp/header/result='FAIL'")
			.to("log:FAIL?showAll=true")
		.otherwise()
			.to("direct:insert");

		from("direct:insert").transacted()
		.to("sql:insert into jobs(startTimestamp, duration, state, message) values (:#startTimestamp, :#duration, 0, :#${body})");
	}

}
